1 /***
2 * SelectEdge
3 *
4 * This represents an edge that
5 * results from a switch statement.
6 */
7
8 package junit.quilt.cover.generic;
9
10 import junit.quilt.exception.InvalidTransitionException;
11 import org.apache.bcel.generic.*;
12
13 public class SelectEdge
14 extends FlowControlEdge
15 {
16 private String expr = null;
17 private int value = -1;
18
19 private boolean isDefault = false;
20
21 public SelectEdge( BlockVertex source,
22 BlockVertex target,
23 String expr,
24 int value )
25 {
26 super( source, target );
27 this.isDefault = false;
28 this.expr = expr;
29 this.value = value;
30 }
31
32 public SelectEdge( BlockVertex source,
33 BlockVertex target,
34 String expr )
35 {
36 super( source, target );
37 this.isDefault = true;
38 this.expr = expr;
39 }
40
41 public void connect( MethodGen method,
42 InstructionList il,
43 InstructionHandle source,
44 InstructionHandle target )
45 throws InvalidTransitionException
46 {
47 if (source.getInstruction() instanceof Select) {
48 Select select =
49 (Select) source.getInstruction();
50
51 if (isDefault) {
52 select.setTarget( target );
53 } else {
54 int matches[] = select.getMatchs();
55 for (int i = 0; i < matches.length; i++) {
56 if (matches[i] == value) {
57 select.setTarget( i, target );
58 }
59 }
60 }
61 } else {
62 throw new InvalidTransitionException("Select expected");
63 }
64 }
65
66 public FlowControlEdge copy( BlockVertex source,
67 BlockVertex target ) {
68 return new SelectEdge( source,
69 target,
70 expr,
71 value );
72 }
73
74 public String toString() {
75 String RC = "[S: ";
76 if (isDefault) {
77 RC = RC + getTarget();
78 } else {
79 RC = RC + expr + "=" + value + " -> " + getTarget();
80 }
81 RC = RC + "]";
82 return RC;
83 }
84 }
85
86
87
88
This page was automatically generated by Maven